package com.it.a01mystream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

public class SteamDemo3 {
    public static void main(String[] args) {
        List< Student> students = new ArrayList<>();
        Student s1= new Student( "蜘蛛精",26,172.5);
        Student s2= new Student( "蜘蛛精",26,172.5);
        Student s3 = new Student( "紫霞", 23, 167.6);
        Student s4= new Student( "白品品", 25,169.0);
        Student s5= new Student( "牛魔王",35, 183.3);
        Student s6= new Student("牛夫人",34, 168.5);
        Collections. addAll(students, s1, s2, s3, s4, s5, s6);
        //需求1：请计算出身高超过168的学生有几人。
        long size = students.stream().filter(higher -> higher.getHeight() > 168).count();
        System.out.println(size);
        //需求2：请找出身高最高的学生对象，并输出。
        Student s = students.stream().max((o1, o2) -> Double.compare(o1.getHeight(), o2.getHeight())).get();
        System.out.println(s);
        //需求3：请找出身高最矮的学生对象，并输出。
        Student ss = students.stream().min((o1, o2) -> Double.compare(o1.getHeight(), o2.getHeight())).get();
        System.out.println(ss);
        //需求4：请找出身高超过170的学生对象，并放到一个新集合中去返回。
    }
}
